﻿using SqlDataAccess;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace QuanLyBanHang.HeThong
{
	public partial class F101_Dang_nhap : Form
	{
		public F101_Dang_nhap()
		{
			InitializeComponent();
			set_initial_form_load();
		}


		#region Private Methods
		private void set_initial_form_load()
		{
			this.Load += F101_Dang_nhap_Load;
			this.m_cmd_dang_nhap.Click += m_cmd_dang_nhap_Click;
			this.m_cmd_thoat.Click += m_cmd_thoat_Click;
		}


		#endregion

		#region Events
		void m_cmd_thoat_Click(object sender, EventArgs e)
		{
			try
			{
				this.Close();
			}
			catch (Exception v_e)
			{
				MessageBox.Show(v_e.ToString());
			}
		}

		void m_cmd_dang_nhap_Click(object sender, EventArgs e)
		{
			try
			{
				using (BKIQuanLyBanHangEntities db = new BKIQuanLyBanHangEntities())
				{
					HT_NGUOI_SU_DUNG v_nsd = db.HT_NGUOI_SU_DUNG
						.FirstOrDefault(x => x.USER_NAME == m_txt_ten_dang_nhap.Text
											&& x.PASSWORD == m_txt_password.Text);
					if (v_nsd == null)
					{
						MessageBox.Show("Tên truy cập hoặc mật khẩu không đúng!");
						m_txt_ten_dang_nhap.Text = "";
						m_txt_password.Text = "";
						m_txt_ten_dang_nhap.Focus();
					}
					else
					//
					{
						this.Hide();
						DangNhap.InitialUser(v_nsd.USER_NAME, v_nsd.PASSWORD,v_nsd.ID);
						F101_Trang_chu v_frm_trang_chu = new F101_Trang_chu();
						v_frm_trang_chu.display_for_user_group(v_nsd.ID_NHOM_NGUOI_DUNG);
						this.Close();
					}
				}

			}
			catch (Exception v_e)
			{
				MessageBox.Show(v_e.ToString());
			}
		}

		void F101_Dang_nhap_Load(object sender, EventArgs e)
		{
			try
			{

			}
			catch (Exception v_e)
			{
				MessageBox.Show(v_e.ToString());
			}
		}
		#endregion

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void m_txt_ten_dang_nhap_TextChanged(object sender, EventArgs e)
        {

        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void m_txt_password_TextChanged(object sender, EventArgs e)
        {

        }

        private void m_cmd_dang_nhap_Click_1(object sender, EventArgs e)
        {

        }

	}
}
